package main.java.model;

public class ElectroValve {
    
    private boolean valueE;
    private int position;
    private int pressure;
    
    //static final variables to change positions id easier
    private static final int OPEN_ID = 0;
    private static final int CLOSED_ID = 1;
    
    /**
     * Constructor ElectroValve
     */
    public ElectroValve() {
        this.valueE = false;
        this.position = OPEN_ID;
        this.pressure = 0;
    }
    
    /**
     * Supply the hydraulic circuit
     * @param hydraulicCircuit : hydraulic circuits
     * @param elementId : the action type
     */
    public void supply(HydraulicCircuit [] hydraulicCircuit, int elementId) {
        if (this.pressure > 0) {
            this.pressure --;
            
            switch (elementId) {
                case 0:
                    hydraulicCircuit[0].setPressure(elementId, hydraulicCircuit[0].getPressure() - 1);
                    break;
                case 1:
                    hydraulicCircuit[0].setPressure(elementId, hydraulicCircuit[0].getPressure() + 1);
                    break;
                case 2:
                    hydraulicCircuit[1].setPressure(elementId, hydraulicCircuit[1].getPressure() - 1);
                    break;
                case 3:
                    hydraulicCircuit[1].setPressure(elementId, hydraulicCircuit[1].getPressure() + 1);
                    break;
                default:
                    break;
            }
        }
    }

    /**
     * Return the position in a string
     * @return String : the position in a string
     */
    public String positionToString() {
        switch (position) {
            case OPEN_ID :
                return "Open";
            case CLOSED_ID :
                return "Closed";
            default :
                return "Default";
        }
    }
    
    /**
     * From the string value of the position
     * Get the number that matches
     * @param positionString : the string
     * @return int : the number
     */
    public int getPositionValue(String positionString) {
        switch (positionString) {
            case "Open" :
                return OPEN_ID;
            case "Closed" :
                return CLOSED_ID;
            default :
                return -1;
        }
    }
    
    public boolean isE() {
        return valueE;
    }

    public void setE(boolean e) {
        valueE = e;
    }

    public int getPosition() {
        return position;
    }

    public void setPosition(int position) {
        this.position = position;
    }
    
    public int getPressure() {
        return pressure;
    }

    public void setPressure(int pressure) {
        this.pressure = pressure;
    }
}
